<%@ page import="icontrolv2.Tarea" %>
<!doctype html>
<html>
  <head>
    <meta name="layout" content="main">
    <g:set var="entityName" value="${message(code: 'tarea.label', default: 'Tarea')}" />
    <title><g:message code="default.edit.label" args="[entityName]" /></title>
    <script type="text/javascript">
    $(document).ready(function(){  
        $(".agregar_comentario").fancybox({  
            'autoScale'     : true,
            'modal'         : false,
            'width'         : 680,  
            'height'        : 450,
            'type'          : 'inline'
        });
      }
    );
    </script>
  </head>
  <body>
    <a href="#edit-tarea" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
    <div class="nav" role="navigation">
      <ul>
        <li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
        <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
        <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
      </ul>
    </div>
    <div id="edit-tarea" class="content scaffold-edit" role="main">
      <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
      <g:if test="${flash.message}">
        <div class="message" role="status">${flash.message}</div>
      </g:if>
      
      <g:if test="${flash.tareaTomada}">
        <div class="message" role="status">${flash.tareaTomada}</div>
      </g:if>
      
      <g:if test="${flash.mensajeError}">
        <div  class="errors message">${flash.mensajeError}</div>
      </g:if>

      <g:if test="${flash.mensajeExito}">
        <div  class="message">${flash.mensajeExito}</div>
      </g:if>
      
      <g:hasErrors bean="${tareaInstance}">
      <ul class="errors" role="alert">
        <g:eachError bean="${tareaInstance}" var="error">
        <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
        </g:eachError>
      </ul>
      </g:hasErrors>
      <g:form method="post" >
        <g:hiddenField name="id" value="${tareaInstance?.id}" />
        <g:hiddenField name="version" value="${tareaInstance?.version}" />
        <fieldset class="form">
          <g:render template="form"/>
        </fieldset>
        <fieldset class="buttons">
          <g:if test="${tareaInstance.estado.getId() == 1}">
            <g:actionSubmit class="edit" action="tomarTarea" onclick="return confirm('¿Desea tomar esta tarea?')" id="${tareaInstance.getId()}" params="[proyectoId: tareaInstance.proyecto.getId()]" value="Tomar Tarea" />
          </g:if>
          
          <g:if test="${tareaInstance.estado.getId() != 3}">
            <g:actionSubmit class="edit" action="pausarTarea" id="tareaInstance.id" params="[proyectoId:tareaInstance.proyecto.id]" value="Pausar Tarea" />
          </g:if>
          
          <g:if test="${tareaInstance.estado.getId() != 4}">
            <g:actionSubmit class="edit" action="terminarTarea" id="tareaInstance.id" params="[proyectoId:tareaInstance.proyecto.id]" value="Terminar Tarea" />
          </g:if>
          
          <g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />
          <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" formnovalidate="" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
          <g:link class="create" action="agregarComentario" id="${tareaInstance.id}" params="[proyectoId:tareaInstance.proyecto.id]" class="agregar_comentario">Agregar Comentario</g:link>
        </fieldset>
      </g:form>
      
      <h1>Comentarios</h1>
      
      <table>
        <tr>
          <th>Fecha</th>
          <th>Comentario</th>
        </tr>
        <g:each in="${tareaInstance.comentarios}" status="i" var="comentario">
        <tr>
          <td>${comentario.fecha}</td>
          <td>${comentario.comentario}</td>
        </tr>
        </g:each>
      </table>
    </div>
  </body>
</html>
